import {defineStore} from "pinia";
import {
    adduserInfo, editUserInfo,
    getCerType,
    getCityProvince,
    getHospitalDepartment,
    getHospitalInfo, getHospitalPerson,
    getHospitalScheduleDoctor, getHospitalSchedulePerson,
    getHospitalScheduleRule, getOrderNo, removeByUserId
} from "@/api/hospital_info";

interface hospitalInfoType {
    hospitalInfo: any,
    hospitalDepartment: any,
    hospitalScheduleRule: any,
    total: string,
    hospitalScheduleDoctor: any,
    firstDayInfo: any,
    users: any,
    docInfo: any,
    provinceInfo: any,
    cerType: any,
    orderId: string
}

const useHospitalInfoStore = defineStore("hospitalInfo", {
    state: (): hospitalInfoType => ({
        hospitalInfo: {},
        hospitalDepartment: [],
        hospitalScheduleRule: {},
        hospitalScheduleDoctor: [],
        total: "",
        //默认存储第一天的日期
        firstDayInfo: {},
        users: [],
        docInfo: {},
        provinceInfo: [],
        cerType: [],
        orderId: ""
    }),
    actions: {
        async getHospitalInfoData(hospitalCode: any) {
            const res: any = await getHospitalInfo(hospitalCode)
            this.hospitalInfo = res.data
        },
        async getHospitalDepartmentData(hospitalCode: any) {
            const res: any = await getHospitalDepartment(hospitalCode)
            this.hospitalDepartment = res.data
        },
        async getHospitalScheduleRuleData(page: number, limit: number, hoscode: string, depcode: string) {
            const res: any = await getHospitalScheduleRule(page, limit, hoscode, depcode)
            this.hospitalScheduleRule = res.data
            this.total = res.data.total
            //默认存储第一天的日期
            this.firstDayInfo = res.data.bookingScheduleList[0]
        },
        async getHospitalScheduleDoctorData(hoscode: string, depcode: string, workDate: string) {
            const res: any = await getHospitalScheduleDoctor(hoscode, depcode, workDate)
            this.hospitalScheduleDoctor = res.data
        },
        async getHospitalPersonData() {
            const res: any = await getHospitalPerson()
            this.users = res.data
        },
        async getHospitalSchedulePersonData(schedule: string) {
            const res: any = await getHospitalSchedulePerson(schedule)
            this.docInfo = res.data
        },
        async getCityProvinceData(parentId: string) {
            const res: any = await getCityProvince(parentId)
            this.provinceInfo = res.data
        },
        async getCerTypeData(cerId: string) {
            const res: any = await getCerType(cerId)
            this.cerType = res.data
        },
        async addUserInfoData(userInfo: any) {
            await adduserInfo(userInfo)
        },
        async editUserInfoData(userInfo: any) {
            await editUserInfo(userInfo)
        },
        async removeByUserIdData(id: string) {
            await removeByUserId(id)
        },
        async getOrderNoData(hoscode: string, scheduleId: string, patientId: string) {
            const res = await getOrderNo(hoscode, scheduleId, patientId)
            this.orderId = res.data
        }
    }
});

export default useHospitalInfoStore
